Coordinate Conversion Scripts
These utilities convert coordinates between pixel space, projected meters, and geographic (longitude/latitude) coordinate systems using GDAL’s transformation capabilities.pixel2longlat.py
Converts pixel coordinates to longitude/latitude coordinates.Usage
Parameters
Pixel sample (column) coordinate
Pixel line (row) coordinate
Input georeferenced image file
Return Values
Outputs to stdout:- Pixel coordinates (sample, line)
- Longitude and latitude in decimal degrees
- Longitude and latitude in DMS (Degrees, Minutes, Seconds) format
How It Works
- Reads the geotransformation matrix from the input file
- Calculates ground coordinates for the pixel center
- Transforms projected coordinates to geographic (lat/long)
- Reports results in both decimal and DMS formats
Example
Notes
- Coordinates are calculated for the center of the pixel
- Input file must have valid geotransform and projection information
- Works with any GDAL-supported georeferenced format
pixel2meters.py
Converts pixel coordinates to X,Y coordinates in the image’s projected coordinate system (typically meters or feet).Usage
Parameters
Pixel sample (column) coordinate
Pixel line (row) coordinate
Input georeferenced image file
Return Values
Outputs to stdout:- Pixel coordinates (sample, line)
- X and Y coordinates in projected units (typically meters)
Example
Notes
- Returns coordinates in the file’s native projection units
- Does not perform coordinate transformation
- Coordinates are for pixel center
longlat2meters.py
Converts longitude/latitude coordinates to X,Y projected coordinates based on an input image’s projection.Usage
Parameters
Longitude in decimal degrees
Latitude in decimal degrees
Input georeferenced image defining the projection
Return Values
Outputs to stdout:- Input longitude and latitude
- Transformed X and Y coordinates in projected units
How It Works
- Reads projection information from input file
- Creates coordinate transformation from geographic to projected
- Transforms the input lon/lat to X/Y meters
Example
Use Cases
- Converting GPS coordinates to map projection
- Preparing coordinates for GIS analysis
- Validating coordinate transformations
meters2longlat.py
Converts X,Y projected coordinates to longitude/latitude based on an input image’s projection.Usage
Parameters
X coordinate in projected units (meters or feet)
Y coordinate in projected units (meters or feet)
Input georeferenced image defining the projection
Return Values
Outputs to stdout:- Input X and Y coordinates
- Transformed longitude and latitude in decimal degrees
- Longitude and latitude in DMS format
Example
Notes
- Performs inverse transformation from projected to geographic
- Useful for converting map coordinates to GPS-compatible format
- Output includes both decimal and DMS formats for convenience
Common Workflow
These scripts work together for various coordinate conversion workflows:Workflow 1: Pixel to Geographic
Workflow 2: Geographic to Pixel
Technical Details
Coordinate Systems
All scripts use GDAL/OSR for coordinate transformations:- Support for any projection defined in the input file
- Automatic handling of datum transformations
- Precise transformation using PROJ library
Pixel Convention
All scripts use pixel center convention:- Adds half pixel offset to ensure center point
- Consistent with most GIS software conventions
Requirements
Troubleshooting
Error: Unable to load PROJ.4 library
Error: Unable to load PROJ.4 library
Ensure GDAL is properly installed with PROJ support:
Incorrect transformations
Incorrect transformations
Verify the input file has correct projection information:
Script returns Usage message
Script returns Usage message
Check that all required parameters are provided in the correct order:
- All three arguments must be present
- Numeric values must be valid
- File must exist and be readable